package com.ms.controller;

import com.ms.common.Result;
import com.ms.pojo.Employee_login;
import com.ms.service.UserService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;


@RestController
@RequestMapping("/user")
@Tag(name = "员工登录注册接口")
public class UserController {
    @Autowired
    private UserService userService;
    /**
     * 登录接口
     */
    @PostMapping ("/login")
    @Operation(summary = "员工登录接口")
    public Result<Employee_login> login(String empUsername, String empPassword) {
        Employee_login employeelogin = userService.login(empUsername, empPassword);
        if (employeelogin != null) {
            // 登录成功，返回用户信息
            return Result.success(employeelogin);
        } else {
            // 登录失败，返回错误信息
            return Result.error("用户名或密码错误");
        }
    }

    /**
     * 员工注册接口
     * @param employeeLogin 登录信息
     * @return 是否成功
     */
    @PostMapping("/register")
    @Operation(summary = "员工注册接口")
    public Result<String> register(@RequestBody Employee_login employeeLogin) {
        boolean success = userService.register(employeeLogin);
        if (success) {
            return Result.success("员工注册成功");
        } else {
            return Result.error("员工注册失败");
        }
    }


}
